<?php

namespace App\Admin\Actions\Audit;

use App\Library\Logic\OperateLogLogic;
use App\Models\ShopFeedbackModel;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class FeedbackAuditAction extends RowAction
{
    public $name = '审核';

    /**
     * handle
     * @param ShopFeedbackModel $model
     * @param Request $request
     * @return Response
     */
    public function handle(ShopFeedbackModel $model, Request $request): Response
    {
        $model->status = $request->status;
        $model->operate_id = Admin::user()->id;
        if ($model->status === 2) $model->fail_reason = $request->reason;
        else $model->ok_reason = $request->reason;
        $model->save();
        OperateLogLogic::add(Admin::user()->user_id, 'admin.feedback.audit');
        return $this->response()->success('操作成功！')->refresh();
    }


    /**
     * form
     * @return void
     */
    public function form(): void
    {
        $this->select('status', '审核')->options([1 => '同意', 2 => '拒绝'])->default(2)->required();
        $this->text('reason', '原因')->attribute('maxlength', 50);
    }
}
